//
//  TutorialScene.cpp
//  Space shooting
//
//  Created by TungNguyen on 9/24/13.
//
//

#include "TutorialScene.h"
#include "StateManager.h"
#include "Constants.h"
#include "CCControlButton.h"
#include "CCScrollView.h"

using namespace cocos2d;

TutorialScene::TutorialScene() {    
    init();
}

TutorialScene::~TutorialScene() {
    removeAllChildrenWithCleanup(true);
}

bool TutorialScene::init() {
    
    if(!CCLayer::init()) {
        
        return false;
    }
    
    CCSize size = CCDirector::sharedDirector()->getWinSize();
        
    CCLabelTTF *logo = CCLabelTTF::create("Tutorial", "Fonts/Spac3 neon.ttf", 20);
    logo->setColor(ccc3(255, 109, 1));
    logo->setPosition(ccp(size.width/2, size.height - 15));
    addChild(logo);
    
    
    CCMenu *menu= CCMenu::create();
    menu->setPosition(CCPointZero);
    
    CCMenuItemImage *homeButton = CCMenuItemImage::create("pause_icon.png", "pause_icon.png", this, menu_selector(TutorialScene::menuItemHome));
    homeButton->setPosition(ccp(size.width - 30, size.height - 30));
    menu->addChild(homeButton);
    
    CCMenuItemImage *preButton = CCMenuItemImage::create("pause_icon.png", "pause_icon.png", this, menu_selector(TutorialScene::menuItemPre));
    preButton->setPosition(ccp(size.width/5, 50));
    menu->addChild(preButton);
    
    CCMenuItemImage *nextButton = CCMenuItemImage::create("CloseNormal.png", "CloseNormal.png", this, menu_selector(TutorialScene::menuItemNext));
    nextButton->setPosition(ccp(size.width - size.width/5, 50));
    menu->addChild(nextButton);
    
    addChild(menu);
    
    // Init Array Image
    arrayImage = new CCArray();
    arrayImage->addObject( CCString::create("tut1.png"));
    arrayImage->addObject( CCString::create("tut2.png"));
    arrayImage->addObject( CCString::create("tut3.png"));
    
    currentIndex = 0;
    
    currentImg = (CCString *)arrayImage->objectAtIndex(currentIndex);
   
    imgTutorial = CCSprite::create(currentImg->getCString());
    imgTutorial->setScale(0.7);
    imgTutorial->setPosition(ccp(size.width/2, size.height/2));
    addChild(imgTutorial);
    
    
    /*
    cocos2d::extension::CCControlButton *button = cocos2d::extension::CCControlButton::create("Button", "Fonts/Spac3 neon.ttf", 20);
    button->setTouchMode(kCCTouchesOneByOne);
    
    cocos2d::extension::CCControlButton *button1 = cocos2d::extension::CCControlButton::create("Button1", "Fonts/Spac3 neon.ttf", 20);
    button1->setPosition(ccp(10, 20));
    button1->setTouchMode(kCCTouchesOneByOne);
    
    cocos2d::extension::CCScrollView *scrollView = cocos2d::extension::CCScrollView::create(CCSize(size.width, size.height/2));
    scrollView->setPosition(ccp(0, size.height/2));
    scrollView->setDirection(cocos2d::extension::kCCScrollViewDirectionHorizontal);
    scrollView->setContentSize(CCSize(100, size.height/2));
    scrollView->setBounceable(true);
    scrollView->addChild(button);
    scrollView->addChild(button1);
    addChild(scrollView);
     */
    
   
    return true;
}

void TutorialScene::menuItemNext(CCObject *object)  {
    
    currentIndex++;
    if(currentIndex >= arrayImage->count()) {
        currentIndex = arrayImage->count() - 1;
    }
   
    currentImg = (CCString *)arrayImage->objectAtIndex(currentIndex);
    imgTutorial->setTexture(CCTextureCache::sharedTextureCache()->addImage(currentImg->getCString()));
    
}

void TutorialScene::menuItemPre(CCObject *object)  {
    
    currentIndex--;
    
    if(currentIndex <= 0) {
        currentIndex = 0;
    }

    currentImg = (CCString *)arrayImage->objectAtIndex(currentIndex);
    imgTutorial->setTexture(CCTextureCache::sharedTextureCache()->addImage(currentImg->getCString()));
}

void TutorialScene::menuItemHome(CCObject *object)  {
    StateManager::getInstance()->switchScene(GAME_STATE_HOME);
}
